package com.sservice.banfu.controller;
import com.sservice.banfu.e.SaleInfo;
import com.sservice.banfu.service.SaleInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *
 * Created by byte_su@163.com on 2018/01/12.
 */
@Controller
@RequestMapping("/admin/saleInfo/")
public class SaleInfoController {

    @Autowired
    SaleInfoService saleInfoService;

    @RequestMapping(value="add",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult add(SaleInfo saleInfo) {
        return new BaseResult(true,String.valueOf(saleInfoService.save(saleInfo)),200);
    }

    @RequestMapping(value="delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult delete(@RequestParam Integer id) {
        return new BaseResult(true,String.valueOf(saleInfoService.deleteById(id)),200);
    }

    @RequestMapping(value="update",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult update(SaleInfo saleInfo) {
        return new BaseResult(true,String.valueOf(saleInfoService.update(saleInfo)),200);
    }

    @RequestMapping("detail/{id}")
    @ResponseBody
    public BaseResult detail(@RequestParam Integer id) {
        SaleInfo saleInfo = saleInfoService.findById(id);
        return new BaseResult(true,saleInfo);
    }

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<SaleInfo> list = saleInfoService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return new ListResult(true, pageInfo);
    }
}
